


class MyThread extends Thread{
    @Override
    public void run(){
        System.out.println("继承 Thread, 重写 run");
    }
}
class MyRunnable implements Runnable{
    @Override
    public void run() {
        System.out.println("实现 Runnable, 重写 run");
    }
}

public class Text {
    public static void main(String[] args) {
        // 1.继承 Thread，重写 run
        MyThread myThread = new MyThread();
        myThread.start();
        // 2.实现 Runnable，重写 run
       Thread thread1 = new Thread(new MyRunnable());
        thread1.start();
        //3.继承 Thread, 重写 run, 使用匿名内部类
        MyThread thread2 = new MyThread() {
            @Override
            public void run() {
                System.out.println("继承 Thread，重写 run，使用匿名内部类");
            }
        };
        thread2.start();
        //4.实现 Runnable, 重写 run, 使用匿名内部类
        Thread thread3 = new Thread(new MyRunnable(){
            @Override
            public void run(){
                System.out.println("实现 Runnable, 重写 run, 使用匿名内部类\n");
            }
        });
        //5.使用 lambda 表达式
        Thread thread4 = new Thread(() -> System.out.println("使用 lambda 表达式"));
        thread4.start();
    }

}